<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Viewer</title>
  <style>
  html {
    height: 100%;
    width: 100%;
  }
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    background: #fff;
    height: 100%;
    margin: 0;
    padding: 0;
    text-decoration: none;
    overflow-y: hidden;
  }
  div {
    margin: 0;
    padding: 0;
  }
  .form {
    height: 100%;
  }
  </style>
</head>
<body>
  <div class="form">
    <div id="iframeEditor"></div>
  </div>
  <script type="text/javascript" src="<%= apiUrl %>"></script>
  <script type="text/javascript">
  var iframeStyleText = '#header-logo, #navbar-logo { display: none !important; } .logo-navbar .navbar-inner { top: 12px !important; }'
  var style = document.createElement('style')

  style.type = 'text/css'
  if (style.styleSheet) {
    style.styleSheet.cssText = iframeStyleText
  } else {
    style.appendChild(document.createTextNode(iframeStyleText))
  }

  var editor
  var connectEditor = function () {
    editor = new DocsAPI.DocEditor('iframeEditor', {
      <%- include("config") %>,
      events: {
        onAppReady: function (e) {
          var iframe = window.frames['frameEditor']
          if (iframe) {
            iframe.document.head.appendChild(style)
          }
          // ls sse-opensource-warning Date.now()
        }
      }
    })
    resize()
  }
  var resize = function () {
    var formEl = document.getElementsByClassName('form')

    if (formEl.length) {
      formEl[0].style.height = screen.availHeight + 'px'
      window.scrollTo(0, -1)
      formEl[0].style.height = window.innerHeight + 'px'
    }
  }

  if (window.addEventListener) {
    window.addEventListener('load', connectEditor)
    window.addEventListener('resize', resize)
  } else if (window.attachEvent) {
    window.attachEvent('onload', connectEditor)
    window.attachEvent('onresize', resize)
  }
  </script>
</body>
</html>
